package lowijs.XfireClient.packet;

import lowijs.XfDroid.FriendDBAdapter;
import lowijs.XfireClient.util.Util;

public class FriendGamePacket extends Packet {
	public FriendGamePacket(byte[] data) {
		int numSids = fromLowHigh(data[9], data[10]);
		long[] friends = new long[numSids];
		long[] gameids = new long[numSids];
		int pos = 11;

		FriendDBAdapter db = FriendDBAdapter.getInstance(null);

		for (int i = 0; i < numSids; i++) {
			byte[] sid = new byte[16];
			System.arraycopy(data, pos, sid, 0, 16);
			friends[i] = db.findMemberBySid(sid);
			pos += 16;
		}

		pos += 11; // jump to the gameids

		for (int i = 0; i < numSids; i++) {
			gameids[i] = Util.intFromBytes(data, pos, 4);
			pos += 4;
		}

		db.updateGames(friends, gameids);
	}
}
